package ${packageName}.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import ${packageName}.dto.${className}AddDTO;
import ${packageName}.dto.${className}ModDTO;
import ${packageName}.vo.${className}Vo;
import ${packageName}.dto.${className}QueryDTO;
import ${packageName}.entity.${className};
import ${packageName}.service.${className}Service;
import com.shoulder.core.api.ApiResult;
import com.shoulder.log.annotation.LogAnnotation;
import com.shoulder.core.fetch.BaseIds;
import com.shoulder.core.page.PageSchema;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import lombok.AllArgsConstructor;
import java.util.List;

/**
* ${comment}管理
*/
@RestController
@AllArgsConstructor
@RequestMapping("/admin/api/v1/${code}/${tableName}")
public class ${className}Controller {

    private final ${className}Service ${className?uncap_first}Service;

    /**
    * 添加${comment}
    *
    * @param addDTO ${comment}添加请求体
    * @return ApiResult<Object>
    * @author ${author!'unKnown'}
    */
    @PostMapping
    @LogAnnotation(type = "添加${comment}")
    public ApiResult<Object> add(@RequestBody @Validated ${className}AddDTO addDTO) {
        this.${className?uncap_first}Service.add(addDTO);
        return ApiResult.ok();
    }

    /**
    * 修改${comment}
    *
    * @param modDTO ${comment}修改请求体
    * @return ApiResult<Object>
    * @author ${author!'unKnown'}
    */
    @PutMapping
    @LogAnnotation(type = "修改${comment}")
    public ApiResult<Object> mod(@RequestBody @Validated ${className}ModDTO modDTO) {
        this.${className?uncap_first}Service.mod(modDTO);
        return ApiResult.ok();
    }

    /**
    * 查询${comment}分页数据
    *
    * @param queryDTO ${comment}查询请求体
    * @return ${comment}分页数据
    * @author ${author!'unKnown'}
    */
    @LogAnnotation(type = "${comment}分页查询", record = false)
    @PostMapping("/page")
    public ApiResult<PageSchema<${className}Vo>> pageQuery(@RequestBody ${className}QueryDTO queryDTO) {
        Page<${className}Vo> page = this.${className?uncap_first}Service.pageQuery(queryDTO);
        return ApiResult.ok(new PageSchema<>(page.getTotal(), page.getRecords()));
    }

    /**
    * 查询${comment}列表数据
    *
    * @param queryDTO ${comment}查询请求体
    * @return ${comment}列表数据
    * @author ${author!'unKnown'}
    */
    @LogAnnotation(type = "${comment}列表查询", record = false)
    @PostMapping("/list")
    public ApiResult<List<${className}Vo>> list(@RequestBody ${className}QueryDTO queryDTO) {
        List<${className}Vo> list = this.${className?uncap_first}Service.listQuery(queryDTO);
        return ApiResult.ok(list);
    }

    /**
    * 批量删除${comment}
    *
    * @param baseIds  ${comment}id集合
    * @return ApiResult<Object>
    * @author ${author!'unKnown'}
    */
    @PostMapping("/rm")
    @LogAnnotation(type = "批量删除${comment}")
    public ApiResult<Object> delete(@RequestBody @Validated BaseIds<String> baseIds) {
        this.${className?uncap_first}Service.batchDel(baseIds);
        return ApiResult.ok();
    }


    /**
    * 根据id删除${comment}
    *
    * @param id ${comment}id
    * @return ApiResult<Object>
    * @author ${author!'unKnown'}
    */
    @DeleteMapping("/{id}")
    @LogAnnotation(type = "删除${comment}")
    public ApiResult<Object> del(@PathVariable String id) {
        this.${className?uncap_first}Service.del(id);
        return ApiResult.ok();
    }


    /**
    * 批量查询${comment}
    *
    * @param baseIds  ${comment}id集合
    * @return ${comment}列表数据
    * @author ${author!'unKnown'}
    */
    @PostMapping("/look")
    @LogAnnotation(type = "批量查询${comment}", record = false)
    public ApiResult<List<${className}Vo>> looks(@RequestBody BaseIds<String> baseIds) {
        List<${className}Vo> list = this.${className?uncap_first}Service.looks(baseIds);
        return ApiResult.ok(list);
    }

    /**
    * 根据id获取${comment}
    *
    * @param id ${comment}id
    * @return ${comment}
    * @author ${author!'unKnown'}
    */
    @GetMapping("/{id}")
    @LogAnnotation(type = "根据id查询${comment}", record = false)
    public ApiResult<${className}Vo> look(@PathVariable String id) {
        ${className}Vo look = this.${className?uncap_first}Service.look(id);
        return ApiResult.ok(look);
    }
}
